﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure;
using Infrastructure.DataTypes;
using StatisticalTest;
using Algorithms;
using System.ComponentModel;
namespace Controllers
{
    class StatisticalAnalysisController<R> where R : ICountable,new()
    {
        List<string> m_implementedTestsInner;
        List<string> m_implementedTestsByUser;
        public BackgroundWorker BackgroundWorker { private get; set; }

        public StatisticalAnalysisController()
        {
            m_implementedTestsInner = new List<string>();
            m_implementedTestsInner.Add("RMSE");
            m_implementedTestsByUser = new List<string>();
            m_implementedTestsByUser.Add("RMSE");
        }
        /// <summary>
        /// inner RMSE tests list 
        /// </summary>
        public List<string> ImplementedTests { get { return m_implementedTestsInner; } }
        /// <summary>
        /// Users  RMSE tets list 
        /// </summary>
        public List<string> ImplementedTestsByUser { get { return m_implementedTestsByUser; } }



        public Dictionary<string, double> RunStatisticalAnalysis(List<User<R>> lUsers, string test, List<string> lAlgorithmNames)
        {
            if (test == "RMSE")
            {
                List<PredictionAlgorithm<R>> lAlgorithms = new List<PredictionAlgorithm<R>>();
                foreach (string sAlgorithm in lAlgorithmNames)
                    lAlgorithms.Add(AlgorithmsFactory<R>.CreatePredictionAlgorithm(sAlgorithm));
                RootMeanSquareError<R> rmse = new RootMeanSquareError<R>();
                rmse.BackgroundWorker = BackgroundWorker;
                return rmse.Score(lAlgorithms, lUsers);
            }
            return null;
        }
    }
}
